package com.yueya.business.senior.model;

import java.util.Map;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.yueya.common.util.DateUtil;
import com.yueya.common.util.UUIDGenerator;

@SuppressWarnings("serial")
public class SeniorHealth extends Model<SeniorHealth> {
	
public static  SeniorHealth dao = new SeniorHealth();
	
	public boolean save(SeniorBase dao) {
		dao.set("senior_health_id", UUIDGenerator.getUUID());
    	dao.set("create_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}

	 
    public boolean update(SeniorBase dao) {
    	dao.set("update_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}
    
    
    @SuppressWarnings("rawtypes")
	public Page paginate (int pageNumber,int pageSize,Map<String,String> map) {
        String select ="SELECT sh.senior_health_id,"
        		+ "sh.senior_id,"
        		+ "sh.health_status,"
        		+ "sh.vision,"
        		+ "sh.hearing,"
        		+ "sh.allergy_drug,"
        		+ "sh.hospital,"
        		+ "sh.hospital_tel,"
        		+ "sh.medical_history,"
        		+ "sh.create_time,"
        		+ "sh.health_reason";  
        
        StringBuffer sql = new StringBuffer(" from  jg_senior_health sh where sb.del_flag='0' ");
        
        for (Map.Entry<String, String> entry : map.entrySet()) {            
       	 if(StrKit.notBlank(entry.getValue())) {
       	   sql.append(" and sh." +entry.getKey()+ "='"+entry.getValue()+"'  ");
       	 }           
        }  
        
       if(StrKit.notBlank(map.get("order"))) {
     	     sql.append(" order by  "+map.get("order"));
       }else {
        	 sql.append(" order by sh.create_time desc,sh.update_time desc " );
       }
        
    	return dao.paginate(pageNumber, pageSize, select, sql.toString());
    }
	

}
